<?php $listeRegion = modele_region::getListeRegion(); ?>
<?php if(isset($_GET['modif_id'])&&$_GET['modif_id']>0): ?>
<?php
$region = new modele_category($_GET['modif_id']);
?>

<a href="index.php?template=regions">retour</a>
<h1>Modifier une région</h1>
<hr style="margin: 5px 0 15px 0;">
<form method="post" enctype="multipart/form-data" action="?template=regions&action=update&modele=category&do=1&modif_id=<?php echo $region->getId(); ?>&modele_id=<?php echo $region->getId(); ?>">
    <div class="columns ten">
        <p style="margin: 10px 0;">Nom :<br/><input type="text" name="modele_title" value="<?php echo $region->getTitle(); ?>" class="titreModele" /></p>
        <p style="margin: 10px 0;"><?php echo PWE::getBaseURL(); ?><input id="permalien" type="text" name="modele_lien" value="<?php echo $region->getPermalien()->getLien(); ?>" style="font-size: 1.2em;" onblur="javascript:validPermalien($(this).val());"/>/</p>        
		<h2 style="margin: 10px 0 0 0; text-align: center;">Texte</h2>
        <textarea id="editor" name="modele_custom_vars[content]"><?php echo $region->getCustomVar('content'); ?></textarea>
        <p style="margin: 10px 0;">Titre SEO : <input type="text" maxlength="255" name="modele_titre_seo" value="<?php echo $region->getTitreSEO(); ?>" style="width: 450px;"/></p>
        <p style="margin: 10px 0;">Description SEO : <textarea  maxlength="512" name="modele_description_seo" style="height: 100px;"><?php echo $region->getDescriptionSEO(); ?></textarea></p>
        <div align="right"><input type="submit" value="Enregistrer" class="pwe-ui-btn"/></div>
    </div>
    <div class="columns five">
        <h3>Statut</h3>
        <select name="modele_statut_id">
            <option value="1" <?php echo($region->getStatutId()==1)?'selected="selected"':''; ?>>Brouillon</option>
            <option value="2" <?php echo($region->getStatutId()==2)?'selected="selected"':''; ?>>Publié</option>
        </select>
    </div>
</form>

<?php elseif(isset($_GET['modif_id'])&&$_GET['modif_id']==0&&isset($_GET['create'])&&$_GET['create']==1): ?>
<?php
$region = new modele_category();
?>

<a href="index.php?template=regions">retour</a>
<h1>Modifier une région</h1>
<hr style="margin: 5px 0 15px 0;">
<form method="post" enctype="multipart/form-data" action="?template=regions&action=create&modele=category&do=1&modele_id=0">
    <div style="float: left; width: 750px;">
        <p style="margin: 10px 0;">Nom :<br/><input type="text" name="modele_title" value="" class="titreModele" /></p>
        <p style="margin: 10px 0;"><?php echo PWE::getBaseURL(); ?><input id="permalien" type="text" name="modele_lien" value="" style="font-size: 1.2em;" onblur="javascript:validPermalien($(this).val());"/>/</p>
		<h2 style="margin: 10px 0 0 0; text-align: center;">Texte</h2>
        <textarea id="editor" name="modele_custom_vars[content]"></textarea>
        <p style="margin: 10px 0;">Titre SEO : <input type="text" maxlength="255" name="modele_titre_seo" value="" style="width: 450px;"/></p>
        <p style="margin: 10px 0;">Description SEO : <textarea  maxlength="512" name="modele_description_seo" style="height: 100px;"></textarea></p>
        <div align="right"><input type="submit" value="Enregistrer" class="pwe-ui-btn"/></div>
    </div>
    <div style="float: left; width: 350px; margin: 0 0 0 15px;">
        <select name="modele_statut_id">
			<option value="2">Publié</option>
			<option value="1">Brouillon</option>
		</select>
    </div>
</form>

<?php else: ?>
<a href="index.php">retour</a>
<h1>Liste des régions</h1>
<hr style="margin: 5px 0 15px 0;">
<table class="liste ui-widget">
    <thead class="ui-widget-header">
        <tr>
            <th>Nom</th>
            <th>Statut</th>
            <th></th>
        </tr>
    </thead>
    <tbody>  
    <?php foreach($listeRegion as $region): ?>
        <tr class="ui-widget-content">
            <td><?php echo $region->getNom(); ?></td>
            <td><?php echo ($region->getCategory()===null || $region->getCategory()->getStatutId()==2)?'<span style="color: #00FF00;">active</span>':'<span style="color: #FF0000;">non active</span>'; ?></td>
            <td>
                <?php if($region->getCategory()!==null): ?><a href="?template=regions&modif_id=<?php echo $region->getCategoryId(); ?>">Modifier/activer</a>
				<?php else: ?><a href="?template=regions&modif_id=0&create=1">Activer</a><?php endif; ?>
            </td>
        </tr>
    <?php endforeach; ?>
    </tbody>
    <tfoot></tfoot>
</table>
<?php endif; ?>